package com.bjesc_b2c.app.appraiset.widget.popupwindow;

import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.bjesc_b2c.app.appraiset.R;
import com.bjesc_b2c.app.appraiset.widget.BasePopupWindow;

/**
 * Created by yidong on 2017/5/17.
 */

public class OrderStatusOperationPop extends BasePopupWindow implements View.OnClickListener {
    private TextView notMetTv, meetNotTradedTv, DealTv;
    private StatusCallback statusCallback;
    public int popupWidth;
    public int popupHeight;

    public OrderStatusOperationPop(Context context, StatusCallback statusCallback) {
        super(context, null);
        this.statusCallback = statusCallback;
    }

    @Override
    protected void initViews() {
        view = inflater.inflate(R.layout.layout_pop_operate, null);
        notMetTv = (TextView) view.findViewById(R.id.tv_not_met);
        meetNotTradedTv = (TextView) view.findViewById(R.id.tv_meet_not_traded);
        DealTv = (TextView) view.findViewById(R.id.tv_deal);
        DealTv.setOnClickListener(this);
        meetNotTradedTv.setOnClickListener(this);
        notMetTv.setOnClickListener(this);
        view.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);//这句很重要 不是获取不到宽高
        popupHeight = view.getMeasuredHeight();
        popupWidth = view.getMeasuredWidth();
    }

    @Override
    protected void setView() {
        super.setView();
        this.setWidth(ViewGroup.LayoutParams.WRAP_CONTENT);
    }

    @Override
    protected int setRootViewId() {
        return R.id.root;
    }
    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.tv_not_met:        //未见面
                if (statusCallback != null) {
                    statusCallback.clueStatus("1");
                }
                break;
            case R.id.tv_meet_not_traded:  //见面未成交
                if (statusCallback != null) {
                    statusCallback.clueStatus("2");
                }
                break;
            case R.id.tv_deal:          //已成交
                if (statusCallback != null) {
                    statusCallback.clueStatus("3");
                }
                break;
        }
    }

    public interface StatusCallback {
        void clueStatus(String status);
    }

    public void showAtView(View parent) {
        int[] location = new int[2];
        parent.getLocationOnScreen(location);
        showAtLocation(parent, Gravity.NO_GRAVITY, (location[0] + parent.getWidth() / 2) - popupWidth / 2, location[1] - popupHeight);
    }
}